<?php
  session_start();
  
  $isSignin = isset($_SESSION['user'])? true : false;
  $user = isset($_SESSION['user'])? $_SESSION['user'] : null;
  $cart = isset($_SESSION['cart'])?$_SESSION['cart']: null;

  $totalNum = 0;
  $totalPrice = 0;
?>
<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>购物车</title>
		<link rel="stylesheet" href="./css/shopcar.css" />
	</head>
	<body>
		<div class="header">
			<img src="img/vancl-logo.png" alt="vancl" />
			<!--未登录-->
			<p class="userInfo">
				您好,欢迎光临凡客诚品！
				<?php if ($isSignin):?>
				<a href="#" class="login"><?=$user['user_name'] ?></a>
				
				<span class="sp2">|</span>
				
				<a href="../action/logout_action.php" class="reg">退出</a>
			    <?php else: ?>
				<a href="signin.php" class="login">登录</a>
				
				<span class="sp2">|</span>
				
				<a href="register.php" class="reg">注册</a>
				<?php endif; ?>
			</p>
			<!--未登录-->
			<!--已登录-->
			<!--<p class="userInfo">
				您好,<span class="username">123334432</span>！
				<a href="">退出登录</a>
				<span class="spacer">|</span>
				<a href="">更换用户</a>
			</p>-->
			<!--已登录-->
			<a href="">帮助中心</a>
		</div>
		<div class="body">
			<p>我的购物车</p>
			<span class="warning"><span class="c_red">温馨提示：</span>1.选购清单中的商品无法保留库存，请您及时结算。2.商品的价格和库存将以订单提交时为准。3.促销活动满减优惠将均摊至商品小计中。</span>
		</div>
		
		
		<!--没有商品-->
		<?php if(empty($cart)): ?>
			<div class="empty">
				您的购物车中没有商品，请您先 <a href="index.php">选购商品»</a>
			</div>
		<?php else: ?>
		<!--没有商品-->
			
			
		<!--有商品-->
		<div class="contents">
			<ul>
				<li><input type="checkbox" name="selectAll" id="selectAll" /><label for="selectAll">全选</label></li>
				<li class="ml_200">商品信息</li>
				<li class="ml_200">单价</li>
				<li class="ml_80">数量</li>
				<li class="ml_80">小计</li>
				<li class="ml_80">操作</li>
			</ul>		
			<?php foreach($cart as $good): ?>
			<div class="content">
				<input type="checkbox" class="sel"/>
				<img src="<?=$good['image'] ?>" alt=""/>
				<span class="gname"><?=$good['name'] ?></span>
				<span class="price">¥<?=$good['price'] ?></span>
				<span class="num"><a href="../action/cart_change_num_action.php?op=1&id=<?=$good['id'] ?>">-</a><input type="text" value="<?=$good['num'] ?>" class="number"/><a href="../action/cart_change_num_action.php?op=2&id=<?=$good['id'] ?>">+</a></span>
				<span class="count">¥<?=$good['num']*$good['price'] ?></span>
				<a href="../action/cart_delete_action.php?id=<?=$good['id'] ?>" class="del">删除</a>
				<?php $totalNum += $good['num'];
                      $totalPrice += $good['num']*$good['price']
				 ?>
			</div>
			<?php endforeach; ?>
		</div>
		<div class="pay">
			<p><a class="delSel">删除选中</a><span class="totalNum">数量总计:<?=$totalNum ?>件</span></p>
			<p>产品金额总计(不含运费): <span class="totalMoney">¥<?=$totalPrice ?></span><a href="index.php">继续购物</a><a href="">去结算</a></p> 
		</div>
	    <?php endif ?>
		<!--有商品-->
		
		<div class="tail">
			<p>Copyright 2007 - 2017 vancl.com All Rights Reserved 京ICP证100557号 京公网安备11010102000579号 出版物经营许可证新出发京批字第直110138号</p>
		</div>
	</body>
</html>
